STEP 13: We are going to calculate the actual slope of the line. To do, we will need the rise (change between y-coordinates) and run (change between x-coordinates)

  • Click the LOGIC tab, then and drag out Delta X.
  • Change the variable name from delta_x to run.
  • Change x2 to netx and x1 to ballx to subtract the two x-coordinates and get the run!

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_axis(100) stage.create_grid_overlay(10, "grey") stage.set_background("soccerfield") ballx = -80 bally = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) ball = codesters.Sprite("soccerball", ballx, bally) netx = 90 nety = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) net = codesters.Sprite("soccernet", netx, nety) net.flip_right_left() #sprite = codesters.Line(x-start, y-start, x-end, y-end, "color") line = codesters.Line(ballx, bally, netx, nety, "blue") slopeguess = float(line.ask("What is the slope of this line?")) rise = nety - bally
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)